//
//  SISSPassengerProgressViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/6/22.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSPassengerProgressViewController.h"
#import "SISSMorePopupView.h"
#import "SISSProgressCell.h"
#import "SISSPickerView.h"
#import "SISSHistoryProgressCell.h"
#import "SISSProgressBottomView.h"
#import "SISSChatViewController.h"
#import "SISSPassengerProgressModel.h"
#import "SISSRecommendedHouseDetailViewController.h"
#import "SISSPassengerResourceDetailVC.h"
#import "SISSProgressModel.h"

#import "SISSUploadBuyerEntrustViewController.h"
#import "SISSBuyerEntrustShowViewController.h"
#import "SISSBuyerEntrustContractModel.h"

#import "SISSPassengerTakeLookRecordViewController.h"

#import "SISSConfirmIntentionHouseViewController.h"

#import "SISSUploadBuyHouseQualificationViewController.h"
#import "SISSBuyHouseQualificationShowViewController.h"

#import "SISSImportantMattersNotiShowViewController.h"
#import "SISSUploadImportantMattersNotiViewController.h"

#import "SISSUploadIntermediaryContractViewController.h"
#import "SISSIntermediaryContractShowViewController.h"

#import "SISSUploadBusinessContractViewController.h"
#import "SISSBusinessContractShowViewController.h"

#import "SISSAddToDoItemViewController.h"
#import "SISSToDoItemShowViewController.h"
#import "SISSAddReminderOfBusinessSettlementViewController.h"
#import "SISSReminderOfBusinessSettlementShowViewController.h"

#import "SISSTextShowViewController.h"
#import "SISSOnlineSignatureContractVerifyShowViewController.h"

//#import "SISSProgressWebViewController.h"
//#import "SISSMortgageLoansViewController.h"

#import "SISSNetworkingManager+PassengerProgress.h"
#import "SISSNetworkingManager+Progress.h"

#import "SISSCommentListViewController.h"

//#import "SISSPassengerProgressRecordInfoModel.h"
//#import "SISSMortgageLoansViewController.h"
//#import "SISSNotaryRootViewController.h"
//#import "SISSForeclosureFloorViewController.h"
//#import "SISSProgressEvaluateViewController.h"

#import "SISSEscrowAccountStartViewController.h" // 监管账户申请
#import "SISSEscrowAccountShowViewController.h"
#import "SISSBusinessContractNotaryViewController.h" // 办理买卖合同公证
#import "SISSBusinessContractNotaryShowViewController.h"
#import "SISSRepaymentRedemptionViewController.h" // 还款赎楼
#import "SISSTransferReservationViewController.h" // 過戶登記預約
#import "SISSTransferReservationShowViewController.h"
#import "SISSMortgageAppointmentViewController.h" // 按揭预约信息登记
#import "SISSMortgageAppointmentShowViewController.h"
#import "SISSPropertyCenterCheckMortgageViewController.h" // 产权登记中心办理抵押
#import "SISSPropertyCenterCheckMortgageShowViewController.h"
#import "SISSEscrowUnfreezeFillInViewController.h" // 监管解冻
#import "SISSEscrowUnfreezeShowViewController.h"
#import "SISSHandHouseViewController.h"

static NSString *passengerProgressCellReuseID = @"passengerProgressCellReuseID";
static NSString *passengerHistoryProgressCellReuseID = @"passengerHistoryProgressCellReuseID";
@interface SISSPassengerProgressViewController ()<UITableViewDelegate,UITableViewDataSource,SISSMorePopupViewDelegate,SISSProgressBottomViewDelegate>

/* tableView */
@property (weak, nonatomic) SISSBaseTableView *tableView;
/* bottomView */
@property (weak, nonatomic) SISSProgressBottomView *bottomView;

/// 进度信息记录模型
@property (strong, nonatomic) SISSPassengerProgressRecordInfoModel *passengerProgressInfoModel;

/* 数据 */
@property (strong, nonatomic) NSMutableArray<SISSProgressModel *> *dataArrM;
@property (copy, nonatomic) NSArray<SISSProgressModel *> *localDataArr;
@property (copy, nonatomic) NSArray *nodeTypeArr;

/* 合同文本数据 */
@property (copy, nonatomic) NSArray *contractDataArr;

@end

@implementation SISSPassengerProgressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    WeakSelf
    [kSISSRefresh prepareHeaderRefresh:self.tableView loadDataBlock:^{
        kSISSRefresh.refreshType = SISSRefressTypeUpDown;
        // 获取合作记录时间和id信息
        [weakSelf requestPassengerProgressRecordInfo];
    }];
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // 获取合作记录时间和id信息
    [self requestPassengerProgressRecordInfo];
}


#pragma mark - 代理
#pragma mark -- UITableViewDelegate & UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArrM.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SISSProgressCell *cell = [tableView dequeueReusableCellWithIdentifier:passengerProgressCellReuseID forIndexPath:indexPath];
    
    // 优化从外面点击进入的体验
    //        NSInteger progress = self.passengerProgressInfoModel ? (self.passengerProgressInfoModel.progress == 1 ? 2 : self.passengerProgressInfoModel.progress) : (self.passengerProgressModel.progress == 1 ? 2 : self.passengerProgressModel.progress);
    NSInteger progress = self.passengerProgressInfoModel.progress;
    cell.isFisrtCell = indexPath.row == 0;
    cell.isLastCell = indexPath.row == self.dataArrM.count - 1;
    if (progress < 11) {
        if (progress > indexPath.row) {
            cell.progressStatus = 1;
            cell.topIsDash = NO;
            cell.bottomIsDash = NO;
            cell.userInteractionEnabled = YES;
        } else if (progress == indexPath.row) {
            cell.topIsDash = NO;
            cell.progressStatus = self.isHistory ? 3 : 2;
            cell.bottomIsDash = YES;
            cell.userInteractionEnabled = !self.isHistory;
        } else {
            cell.progressStatus = 3;
            cell.topIsDash = YES;
            cell.bottomIsDash = YES;
            cell.userInteractionEnabled = NO;
        }
    } else {
        cell.userInteractionEnabled = YES;
        progress = progress + self.passengerProgressInfoModel.lstofnode.count;
        if (self.passengerProgressInfoModel.progress == 11 && self.isHistory) progress += 2;
        if (progress > indexPath.row) {
            cell.progressStatus = 1;
            cell.topIsDash = NO;
            cell.bottomIsDash = NO;
            if (self.passengerProgressInfoModel.lstofnode.count > indexPath.row - (self.localDataArr.count - 2)) {
                cell.timeStr = [NSDate yyr_stringToString:self.passengerProgressInfoModel.lstofnode[indexPath.row - (self.localDataArr.count - 2)].insertTime];
            } else {
                cell.timeStr = [self getTimeStrWithIndex:indexPath.row];
            }
            if (self.dataArrM.count-2 == indexPath.row && self.passengerProgressInfoModel.isVerify != 2) {
                cell.userInteractionEnabled = !self.isHistory;
            }
        }  else {
            cell.topIsDash = NO;
            cell.progressStatus = self.passengerProgressModel.progress == 12 ? 1 : 2;
            cell.bottomIsDash = NO;
            cell.userInteractionEnabled = YES;
            cell.timeStr = [self getTimeStrWithIndex:indexPath.row];
        }
    }
    cell.title = self.dataArrM[indexPath.row].title;
    cell.timeStr = [self getTimeStrWithIndex:indexPath.row];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    switch (indexPath.row) {
        case 0: { // 卖家发布房源信息
            SISSPassengerResourceDetailVC *vc = [[SISSPassengerResourceDetailVC alloc] init];
            vc.isHideBottomButton = YES;
            vc.passengerModel = self.passengerProgressModel.demand;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        case 1: { // 中介推荐客源
            SISSRecommendedHouseDetailViewController *vc = [[UIStoryboard storyboardWithName:@"Progress" bundle:nil] instantiateViewControllerWithIdentifier:@"SISSRecommendedHouseDetailViewController"];
            vc.title = @"推荐的房源";
            vc.adbpId = self.passengerProgressModel.adbpId;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        case 2: { // 上传已签署的《二手房买方委托合同》
            
            if (self.passengerProgressInfoModel.hasCommissionContract == 1) {
                SISSBuyerEntrustShowViewController *vc = [[SISSBuyerEntrustShowViewController alloc] init];
                vc.abpId = self.passengerProgressModel.adbpId;
                vc.popBackClassType = SISSProgressPopBackClassTypePassenger;
                vc.isHistory = self.isHistory;
                [self.navigationController pushViewController:vc animated:YES];
            } else {
                if (self.passengerProgressInfoModel.businessStatus == 2) {
                    [self alertActionAlertWithTitle:@"提示" message:@"对方已开启拒绝接收您的请求"];
                    return;
                }
                SISSUploadBuyerEntrustViewController *vc = [[SISSUploadBuyerEntrustViewController alloc] init];
                vc.abpId = self.passengerProgressModel.adbpId;
                vc.popBackClassType = SISSProgressPopBackClassTypePassenger;
                [self.navigationController pushViewController:vc animated:YES];
            }
        }
            break;
            
        case 3: { // 实地看房，添加看房记录、照片
            SISSPassengerTakeLookRecordViewController *vc = [[SISSPassengerTakeLookRecordViewController alloc] init];
            vc.passengerProgressModel = self.passengerProgressModel;
            vc.isHistory = self.isHistory;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        case 4: { // 上传已经签署的《购房资格审核信息表》
            
            if (self.passengerProgressInfoModel.hasQualification == 1) {
                SISSBuyHouseQualificationShowViewController *vc = [[SISSBuyHouseQualificationShowViewController alloc] init];
                vc.passengerProgressModel = self.passengerProgressModel;
                vc.passengerProgressRecordInfoModel = self.passengerProgressInfoModel;
                vc.isHistory = self.isHistory;
                [self.navigationController pushViewController:vc animated:YES];
            } else {
                SISSUploadBuyHouseQualificationViewController *vc = [[SISSUploadBuyHouseQualificationViewController alloc] init];
                vc.passengerProgressModel = self.passengerProgressModel;
                vc.passengerProgressRecordInfoModel = self.passengerProgressInfoModel;
                [self.navigationController pushViewController:vc animated:YES];
            }
            
        }
            break;
            
        case 5: { // 确定购买房源
            SISSConfirmIntentionHouseViewController *vc = [[SISSConfirmIntentionHouseViewController alloc] init];
            vc.passengerProgressModel = self.passengerProgressModel;
            vc.passengerProgressRecordInfoModel = self.passengerProgressInfoModel;
            vc.isHistory = self.isHistory;
            vc.hasConfirm = self.passengerProgressInfoModel.tradeBusinessType > 0;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        case 6: { // 上传已签署的《二手房交易买方重要事项告知书》
            
            if (self.passengerProgressInfoModel.hasbuyerNoti == 1) {
                SISSImportantMattersNotiShowViewController *vc = [[SISSImportantMattersNotiShowViewController alloc] init];
                vc.passengerProgressModel = self.passengerProgressModel;
                vc.passengerProgressRecordInfoModel = self.passengerProgressInfoModel;
                vc.isHistory = self.isHistory;
                [self.navigationController pushViewController:vc animated:YES];
            } else {
                if (self.passengerProgressInfoModel.businessStatus == 2) {
                    [self alertActionAlertWithTitle:@"提示" message:@"对方已开启拒绝接收您的请求"];
                    return;
                }
                SISSUploadImportantMattersNotiViewController *vc = [[SISSUploadImportantMattersNotiViewController alloc] init];
                vc.passengerProgressModel = self.passengerProgressModel;
                vc.passengerProgressRecordInfoModel = self.passengerProgressInfoModel;
                [self.navigationController pushViewController:vc animated:YES];
            }
        }
            break;
            
        case 7: { // 上传已签署的《二手房交易卖方重要事项告知书》
        
            if (self.passengerProgressInfoModel.hassellerNoti == 1) {
                SISSImportantMattersNotiShowViewController *vc = [[SISSImportantMattersNotiShowViewController alloc] init];
                vc.isSellerNoti = YES;
                vc.passengerProgressModel = self.passengerProgressModel;
                vc.passengerProgressRecordInfoModel = self.passengerProgressInfoModel;
                vc.isHistory = self.isHistory;
                [self.navigationController pushViewController:vc animated:YES];
            } else {
                if (self.passengerProgressInfoModel.businessStatus == 2) {
                    [self alertActionAlertWithTitle:@"提示" message:@"对方已开启拒绝接收您的请求"];
                    return;
                }
                SISSUploadImportantMattersNotiViewController *vc = [[SISSUploadImportantMattersNotiViewController alloc] init];
                vc.isSellerNoti = YES;
                vc.passengerProgressModel = self.passengerProgressModel;
                vc.passengerProgressRecordInfoModel = self.passengerProgressInfoModel;
                [self.navigationController pushViewController:vc animated:YES];
            }
        }
            break;
            
        case 8: { // 上传已签署的《居间服务合同》
            
            if (self.passengerProgressInfoModel.hasintermediaryContract == 1) {
                SISSIntermediaryContractShowViewController *vc = [[SISSIntermediaryContractShowViewController alloc] init];
                vc.passengerProgressModel = self.passengerProgressModel;
                vc.passengerProgressRecordInfoModel = self.passengerProgressInfoModel;
                vc.isHistory = self.isHistory;
                [self.navigationController pushViewController:vc animated:YES];
            } else {
                if (self.passengerProgressInfoModel.businessStatus == 2) {
                    [self alertActionAlertWithTitle:@"提示" message:@"对方已开启拒绝接收您的请求"];
                    return;
                }
                SISSUploadIntermediaryContractViewController *vc = [[SISSUploadIntermediaryContractViewController alloc] init];
                vc.passengerProgressModel = self.passengerProgressModel;
                vc.passengerProgressRecordInfoModel = self.passengerProgressInfoModel;
                [self.navigationController pushViewController:vc animated:YES];
            }
        }
            break;
            
        case 9: {// 上传网签后的《二手房买卖合同》
            if (self.passengerProgressInfoModel.hasBusinessContract == 1) {
                SISSBusinessContractShowViewController *vc = [[SISSBusinessContractShowViewController alloc] init];
//                vc.title = @"《深圳市二手房买卖合同》";
                vc.isHistory = self.isHistory;
                vc.passengerProgressModel = self.passengerProgressModel;
                vc.passengerProgressRecordInfoModel = self.passengerProgressInfoModel;
                [self.navigationController pushViewController:vc animated:YES];
            } else {
                SISSUploadBusinessContractViewController *vc = [[SISSUploadBusinessContractViewController alloc] init];
                //                vc.title = @"录入《深圳市二手房买卖合同》";
                vc.passengerProgressModel = self.passengerProgressModel;
                vc.passengerProgressRecordInfoModel = self.passengerProgressInfoModel;
                [self.navigationController pushViewController:vc animated:YES];
            }
        }
            break;
            
        case 10: {// 系统核验网签合同
            if (self.passengerProgressInfoModel.isVerify == 0) {
                SISSTextShowViewController *vc = [[SISSTextShowViewController alloc] init];
                vc.title = @"系统核验网签合同";
                vc.textStr = @"在三方完成网签合同后交易通系统将自动同网签系统核对交易数据，在核对完成后您可以操作后续流程，请耐心等待系统核验。";
                [self.navigationController pushViewController:vc animated:YES];
            } else if (self.passengerProgressInfoModel.isVerify == 1) {
                SISSOnlineSignatureContractVerifyShowViewController *vc = [[SISSOnlineSignatureContractVerifyShowViewController alloc] init];
                vc.isVerifySuccess = YES;
                vc.passengerProgressModel = self.passengerProgressModel;
                vc.passengerProgressRecordInfoModel = self.passengerProgressInfoModel;
                [self.navigationController pushViewController:vc animated:YES];
            } else if (self.passengerProgressInfoModel.isVerify == 2) {
                SISSOnlineSignatureContractVerifyShowViewController *vc = [[SISSOnlineSignatureContractVerifyShowViewController alloc] init];
                vc.isVerifySuccess = NO;
                vc.passengerProgressModel = self.passengerProgressModel;
                vc.passengerProgressRecordInfoModel = self.passengerProgressInfoModel;
                [self.navigationController pushViewController:vc animated:YES];
            }
        }
            break;
            
        default:
            if (indexPath.row == self.dataArrM.count - 1) {
                if (self.isHistory) {
                    SISSCommentListViewController *vc = [[SISSCommentListViewController alloc] init];
                    vc.passengerProgressModel = self.passengerProgressModel;
                    vc.commentType = 3;
                    [self.navigationController pushViewController:vc animated:YES];
                } else {
                    [self alertConfirmCacellActionAlertWithTitle:@"服务评价提醒" message:@"请在买卖流程完成后再评价，在评价后该业务流程结束，不可以再添加业务节点，您确定要进入评价" leftConfirmTitle:@"取消" rightConfirmTitle:@"进入服务评价" selectLeftBlock:^{
                        
                    } selectRightBlock:^{
                        SISSCommentListViewController *vc = [[SISSCommentListViewController alloc] init];
                        vc.passengerProgressModel = self.passengerProgressModel;
                        vc.commentType = 3;
                        [self.navigationController pushViewController:vc animated:YES];
                    }];
                }
                
            } else if (indexPath.row == self.dataArrM.count - 2) {
                SISSPickerView *pickerView = [[SISSPickerView alloc] initWithFrame:self.view.bounds];
                pickerView.title = @"新增流程节点";
                pickerView.titleArray = @[@"办理公证委托提醒", @"办理资金监管提醒", @"取旧证/注销抵提醒", @"办理买卖合同公证提醒", @"办理过户登记提醒", @"交房提醒", @"按揭办理提醒", @"付款提醒", @"办理赎楼提醒", @"确定担保公司", @"担保公司批单结果", @"二手房交接完成", @"按揭审批结果", @"资金监管结果", @"赎楼结果", @"过户结果", @"房产评估结果"];
                pickerView.isArea = NO;
                pickerView.firstIndex = 7;
                __weak typeof(self) weakself = self;
                pickerView.completion = ^(NSString *firstTitle, NSString *secondTitle, NSInteger firstIndex, NSInteger secondIndex) {
                    if (firstIndex <= 8) {
                        SISSAddToDoItemViewController *vc = [[SISSAddToDoItemViewController alloc] init];
                        vc.passengerProgressModel = weakself.passengerProgressModel;
                        vc.passengerProgressRecordInfoModel = weakself.passengerProgressInfoModel;
                        vc.toDoItemStr = firstTitle;
                        vc.business_type = 1;
                        vc.nodeType = weakself.nodeTypeArr[firstIndex];
                        [self.navigationController pushViewController:vc animated:YES];
                    } else if (firstIndex > 8) {
                        SISSAddReminderOfBusinessSettlementViewController *vc = [[SISSAddReminderOfBusinessSettlementViewController alloc] init];
                        vc.passengerProgressModel = weakself.passengerProgressModel;
                        vc.passengerProgressRecordInfoModel = weakself.passengerProgressInfoModel;
                        vc.toDoItemStr = firstTitle;
                        vc.business_type = 2;
                        vc.nodeType = weakself.nodeTypeArr[firstIndex];
                        [self.navigationController pushViewController:vc animated:YES];
                    }
                    
                };
            }else if (self.dataArrM[indexPath.row].jumpNum == 1) {
                
                SISSToDoItemShowViewController *vc = [[SISSToDoItemShowViewController alloc] init];
                vc.additionalNodeModel = self.passengerProgressInfoModel.lstofnode[indexPath.row - (self.localDataArr.count - 2)];
                [self.navigationController pushViewController:vc animated:YES];
                
            } else if (self.dataArrM[indexPath.row].jumpNum == 2) {
                SISSReminderOfBusinessSettlementShowViewController *vc = [[SISSReminderOfBusinessSettlementShowViewController alloc] init];
                vc.additionalNodeModel = self.passengerProgressInfoModel.lstofnode[indexPath.row - (self.localDataArr.count - 2)];
                [self.navigationController pushViewController:vc animated:YES];
            }
            break;
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 88;
}

#pragma mark -- SISSMorePopupViewDelegate 删除 举报
- (void)morePopupViewSelectedWithIndex:(NSInteger)index {
    
    if (self.passengerProgressModel.progress > 2) { // 举报
        [self reportPassenger];
    } else {
        if (index == 0) { // 删除
            NSString *str = @"删除后不可恢复，您确定删除吗？";
            NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
            paragraphStyle.alignment = NSTextAlignmentLeft;
            
            NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13], NSForegroundColorAttributeName: COLOR(0x334A60), NSParagraphStyleAttributeName: paragraphStyle}];
            
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"删除" message:nil preferredStyle:UIAlertControllerStyleAlert];
            
            [alertC setValue:attr forKey:@"attributedMessage"];
            
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"取消");
            }];
            [alertC addAction:cancelAction];
            
            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"确定");
                
                [self deletePassengerProgress];
            }];
            [alertC addAction:okAction];
            
            [self presentViewController:alertC animated:YES completion:nil];
        } else { // 举报
            [self reportPassenger];
        }
    }
}

#pragma mark -- SISSProgressBottomViewDelegate 底部头像、电话、在线咨询
- (void)clickBottomButtonWithIndex:(NSInteger)index {
    
    if (self.passengerProgressInfoModel.businessStatus == 2 && index == 1) {
//        [self alertActionAlertWithTitle:@"提示" message:@"对方已开启拒绝接收您的请求"];
        return;
    }
    if (index == 0) { // 点击头像或名字的
        NSLog(@"人员信息");
//        [kNetworkManager requestPersonInfoWithSpId:self.passengerProgressModel.spId success:^(SISSPersonInfoModel *personInfo) {
//            
//            SISSInfomationViewController *vc = [[UIStoryboard storyboardWithName:@"Mine" bundle:nil] instantiateViewControllerWithIdentifier:@"SISSInfomationViewController"];
//            vc.personInfo = personInfo;
//            
//            vc.spId = self.passengerProgressModel.spId;
//            [self.navigationController pushViewController:vc animated:YES];
//            
//        } failed:^(NSError *error) {
//            
//            NSLog(@"%@",error);
//        }];
    } else if (index == 1) { // 点击拨打电话
        
        if (self.passengerProgressInfoModel.progress < 3) {
            [self alertActionAlertWithTitle:@"不能拨号" message:@"没有签署委托合同，暂不能拨号！"];
        } else {
            
            UIWebView * callWebview = [[UIWebView alloc] init];
            [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",self.passengerProgressModel.phoneNumber]]]];
            [[UIApplication sharedApplication].keyWindow addSubview:callWebview];
        }
    } else { // 点击联系人
        
        SISSChatViewController *chatVC = [[SISSChatViewController alloc] initWithConversationChatter:self.passengerProgressInfoModel.imAccount conversationType:EMConversationTypeChat];
        SISSContactModel *model = [[SISSContactModel alloc] init];
        model.name = self.passengerProgressModel.name;
        model.accountType = 3;
        model.portrait = self.passengerProgressInfoModel.portrait;
        chatVC.contactModel = model;
        chatVC.title = self.passengerProgressModel.name;
        [self.navigationController pushViewController:chatVC animated:YES];
    }
}

#pragma mark - 点击事件
#pragma mark -- 右上角更多按钮点击事件
- (void)rightMoreItemClickAction {
    
    NSArray *titleArr =  self.passengerProgressModel.progress > 2 ? @[@"举报"] : @[@"删除", @"举报"];
    SISSMorePopupView *moreView = [[SISSMorePopupView alloc] initWithTitles:titleArr];
    moreView.delegate = self;
    [moreView show];
}

#pragma mark - 加载数据
#pragma mark -- 获取合作记录时间和id信息
- (void)requestPassengerProgressRecordInfo {
    
    WeakSelf
    [kNetworkManager requestPassengerProgressRecordInfoWithAdbpId:self.passengerProgressModel.adbpId success:^(SISSPassengerProgressRecordInfoModel *progressInfoModel) {
        weakSelf.passengerProgressInfoModel = progressInfoModel;
        weakSelf.bottomView.businessStatus = progressInfoModel.businessStatus;
        
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            
            weakSelf.bottomView.iconUrlStr = progressInfoModel.portrait;
            
            [weakSelf.dataArrM removeAllObjects];
            [weakSelf.dataArrM addObjectsFromArray:weakSelf.localDataArr];
            for (SISSAdditionalNodeModel *additionalNode in progressInfoModel.lstofnode) {
                SISSProgressModel *model = [[SISSProgressModel alloc] init];
                model.title = additionalNode.progressTitle;
                model.jumpNum = additionalNode.businessType;
                [weakSelf.dataArrM insertObject:model atIndex:weakSelf.dataArrM.count-2];
            }
            [weakSelf.tableView.mj_header endRefreshing];
            [weakSelf.tableView reloadData];
        }];
        
    } failed:^(NSError *error) {
        [weakSelf.tableView.mj_header endRefreshing];
        NSLog(@"%@",error);
    }];
   
}

#pragma mark -- 删除请求
- (void)deletePassengerProgress {
    
    [kNetworkManager deletePassengerProgressWithHouseAdbpId:self.passengerProgressModel.adbpId successBlock:^(id) {
        
        if (self.deleteCompletedBlock) {
            self.deleteCompletedBlock();
        }
        [self.navigationController popViewControllerAnimated:YES];
        
    } failed:^(NSError *error) {
        
        NSLog(@"%@",error);
    }];
}

#pragma mark -- 举报
- (void)reportPassenger {
    SISSReportViewController *vc = [[SISSReportViewController alloc] init];
    vc.isReportPassenger = YES;
    vc.passengerModel = self.passengerProgressModel.demand;
    [self.navigationController pushViewController:vc animated:YES];
}


/**
 根据indexPath获取对应的时间字符串
 
 @param index index
 @return 返回对应的时间字符串
 */
- (NSString *)getTimeStrWithIndex:(NSInteger)index {
    
    NSString *timeStr;
    switch (index) {
        case 0:
            timeStr = [NSDate yyr_stringToString:self.passengerProgressInfoModel.insertTime];
            break;
        case 1:
            timeStr = [NSDate yyr_stringToString:self.passengerProgressInfoModel.recommendTime];
            break;
        case 2:
            timeStr = [NSDate yyr_stringToString:self.passengerProgressInfoModel.commissionTime];
            break;;
        case 3:
            timeStr = [NSDate yyr_stringToString:self.passengerProgressInfoModel.takelookTime];
            break;
        case 4:
            timeStr = [NSDate yyr_stringToString:self.passengerProgressInfoModel.qualificationTime];
            break;
            
        case 6:
            timeStr = [NSDate yyr_stringToString:self.passengerProgressInfoModel.sellerNotiTime];
            break;
        case 7:
            timeStr = [NSDate yyr_stringToString:self.passengerProgressInfoModel.buyerNotiTime];
            break;
        case 8:
            timeStr = [NSDate yyr_stringToString:self.passengerProgressInfoModel.intermediaryContractTime];
            break;
        case 9:
            timeStr = [NSDate yyr_stringToString:self.passengerProgressInfoModel.businessContractTime];
            break;
            
        default:
            if (index == self.dataArrM.count - 1) {
                timeStr = [NSDate yyr_stringToString:self.passengerProgressInfoModel.serviceCommentTime];
            } else {
                timeStr = @" ";
            }
            break;
    }
    return timeStr;
}


#pragma mark - navigationItem
- (void)setupNavigationItems {
    [super setupNavigationItems];
    
    self.navigationItem.rightBarButtonItem = self.isHistory ? nil : [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"more..."] style:UIBarButtonItemStylePlain target:self action:@selector(rightMoreItemClickAction)];
}


#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    SISSBaseTableView *tableView = [[SISSBaseTableView alloc] init];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [tableView registerClass:[SISSProgressCell class] forCellReuseIdentifier:passengerProgressCellReuseID];
    [tableView registerClass:[SISSHistoryProgressCell class] forCellReuseIdentifier:passengerHistoryProgressCellReuseID];
    [self.view addSubview:tableView];
    self.tableView = tableView;
    
    SISSProgressBottomView *bottomView = [[SISSProgressBottomView alloc] init];
    bottomView.delegate = self;
    bottomView.name = self.passengerProgressModel.name;
    [self.view addSubview:bottomView];
    self.bottomView = bottomView;
    
    // 自动布局
    WeakSelf
    CGFloat bottomViewHeight = 44.0;
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(weakSelf.view);
        make.bottom.equalTo(bottomView.mas_top);
    }];
    
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(bottomViewHeight);
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.bottom.equalTo(weakSelf.view);
        }
    }];
}

#pragma mark - 懒加载
- (NSArray<SISSProgressModel *> *)localDataArr {
    if (!_localDataArr) {
        NSArray *arr1 = @[
                          @{@"title" : @"买家发布客源信息"},
                          @{@"title" : @"中介推荐房源"},
                          @{@"title" : @"上传已签署的《二手房买方委托合同》"},
                          @{@"title" : @"实地看房，添加看房记录、照片"},
                          @{@"title" : @"上传已经签署的《购房资格审核信息表》"},
                          @{@"title" : @"确定购买房源"},
                          @{@"title" : @"上传已签署的《二手房交易买方重要事项告知书》"},
                          @{@"title" : @"上传已签署的《二手房交易卖方重要事项告知书》"},
                          @{@"title" : @"上传已签署的《居间服务合同》"},
                          @{@"title" : @"上传网签后的《二手房买卖合同》"},
                          @{@"title" : @"系统核验网签合同"},
                          @{@"title" : @"新增流程节点"},
                          @{@"title" : @"服务评价"},
                          ];
        _localDataArr = [NSArray yy_modelArrayWithClass:[SISSProgressModel class] json:arr1];
    }
    if (self.passengerProgressInfoModel.isVerify == 2) {
        NSArray *arr1 = @[
                          @{@"title" : @"买家发布客源信息"},
                          @{@"title" : @"中介推荐房源"},
                          @{@"title" : @"上传已签署的《二手房买方委托合同》"},
                          @{@"title" : @"实地看房，添加看房记录、照片"},
                          @{@"title" : @"上传已经签署的《购房资格审核信息表》"},
                          @{@"title" : @"确定购买房源"},
                          @{@"title" : @"上传已签署的《二手房交易买方重要事项告知书》"},
                          @{@"title" : @"上传已签署的《二手房交易卖方重要事项告知书》"},
                          @{@"title" : @"上传已签署的《居间服务合同》"},
                          @{@"title" : @"上传网签后的《二手房买卖合同》"},
                          @{@"title" : @"系统核验网签合同"},
                          @{@"title" : @"服务评价"},
                          ];
        _localDataArr = [NSArray yy_modelArrayWithClass:[SISSProgressModel class] json:arr1];
    }
    return _localDataArr;
}
- (NSMutableArray<SISSProgressModel *> *)dataArrM {
    if (!_dataArrM) {
        _dataArrM = [NSMutableArray array];
        [_dataArrM addObjectsFromArray:self.localDataArr];
    }
    return _dataArrM;
}
- (NSArray *)nodeTypeArr {
    if (!_nodeTypeArr) {
        _nodeTypeArr = @[@"gzwt_tips", @"zjjg_tips", @"jzdy_tips", @"mmhtgz_tips", @"ghdj_tips", @"jf_tips", @"aj_tips", @"fk_tips", @"sl_tips", @"dbgs_tips", @"dbgspd_tips", @"esfjj_tips", @"ajspjg_tips", @"zjjgjg_tips", @"sljg_tips", @"gljg_tips", @"fcpgjg_tips"];
    }
    return _nodeTypeArr;
}

- (NSArray *)contractDataArr {
    if (!_contractDataArr) {
        //获取plist
        NSURL *url = [[NSBundle mainBundle] URLForResource:@"ProgressContractsUrl" withExtension:@"plist"];
        
        //根据plist加载数组
        _contractDataArr = [NSArray arrayWithContentsOfURL:url];
    }
    return _contractDataArr;
}

@end
